﻿#If (Not WINDOWS_PHONE) And (Not NETFX_CORE) Then

Imports Microsoft.Xna.Framework.Audio
Imports Microsoft.Xna.Framework.Graphics
Imports System.Runtime.CompilerServices
Imports System.IO
Imports Runa.Common.Helper

Namespace Global.Runa.Resources.ContentManagers

    Public Class FileSystmContentManager
        Inherits BasicContentManager

        Public Property FileSystemRootDirectory() As DirectoryInfo

        Public Sub New(serviceProvider As System.IServiceProvider)
            MyBase.New(serviceProvider)
            Dim appPath = System.Reflection.Assembly.GetEntryAssembly().Location
            Me.FileSystemRootDirectory = New DirectoryInfo(Path.Combine(appPath, "Content"))
        End Sub

        ''' <summary>
        ''' Initialize a new FileSystmContentManager by a full file system path.
        ''' </summary>
        ''' <param name="serviceProvider"></param>
        ''' <param name="rootDirectory">
        ''' Full path of the content directory.
        ''' </param>
        ''' <remarks></remarks>
        Public Sub New(serviceProvider As System.IServiceProvider, rootDirectory As String)
            MyBase.New(serviceProvider, rootDirectory)
            Me.FileSystemRootDirectory = New DirectoryInfo(rootDirectory)
        End Sub

        Public Overrides Function Exists(ByVal assetName As String) As Boolean
            Dim fi = New FileInfo(Path.Combine(Me.FileSystemRootDirectory.FullName, assetName))
            Return fi.Exists
        End Function

        Protected Overrides Function OpenStream(assetName As String) As System.IO.Stream
            Dim fi = New FileInfo(Path.Combine(Me.FileSystemRootDirectory.FullName, assetName))
            Return New FileStream(fi.FullName, FileMode.Open)
        End Function

    End Class

End Namespace

#End If